package com.aps.server.controller;

import com.aps.common.code.DistributedSnowflakeIdGenerator;
import com.aps.common.entity.Result;
import com.aps.common.page.PageQuery;
import com.aps.common.page.TableDataInfo;
import com.aps.server.dto.EquipSchedulingResultDto;
import com.aps.server.dto.PlanComparisonDto;
import com.aps.server.dto.QueryParamEquipScheduling;
import com.aps.server.dto.SchedulingPlanGenerateDto;
import com.aps.server.service.PlanComparisonService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author nbZhuozh
 * @Date 2025-10-23  14:01
 **/
@Slf4j
@RestController
@RequestMapping("/api/plan-compare")
@RequiredArgsConstructor
@Tag(name = "方案对比", description = "方案对比api")
public class PlanComparisonController {

    @Resource
    private PlanComparisonService planComparisonService;

    /**
     * 获取方案比对的方案列表
     */
    @GetMapping("query-constraint-list")
    public Result<List<SchedulingPlanGenerateDto>> queryConstraintList(@RequestParam(name = "constrantIds") String constrantIds){
        if (StringUtils.isEmpty(constrantIds)) {
            return Result.error("查询生成方案配置失败，未获取到配置id");
        }
        List<SchedulingPlanGenerateDto> schedulingPlanGenerateDtos = planComparisonService.queryConstraintList(constrantIds);
        return Result.success(schedulingPlanGenerateDtos);
    }


    /**
     * 获取方案对应的 排期表格
     * @param pageQuery
     * @return
     */
    @PostMapping("query-plan-list")
    public Result<TableDataInfo<EquipSchedulingResultDto>> queryPlanListByConfigId(
            @RequestBody PageQuery<QueryParamEquipScheduling> pageQuery) {
        if(StringUtils.isEmpty(pageQuery.getCondition().getConstraintId())){
            return Result.error("未获取到配置id");
        }
        IPage<EquipSchedulingResultDto> planComparisonDtoIPage = planComparisonService.queryPlanListByConfigId(pageQuery);
        return Result.success(TableDataInfo.build(planComparisonDtoIPage));
    }




    //TODO 根据约束id 查询对应算法出的计划、配置、甘特图数据
//    @GetMapping("query-config-result")
//    public Result<PlanComparisonDto> gen(@RequestParam(name = "configId" , required = true) String configId) {
//        if(StringUtils.isEmpty(configId)){
//            Result<PlanComparisonDto> result = new Result<>();
//            return result.error("未获取到配置id");
//        }
//        planComparisonService.
//        return Result.success(prefix + DistributedSnowflakeIdGenerator.generate20DigitId());
//    }

    //TODO 查询方案甘特图数据

    //TODO 查询KPI指标数据

    //TODO 查询方案对比分析数据

}
